package com.cosmetics.groupware;

import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);

	@Autowired
	protected HomeService homeService;
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value="/main.do", method=RequestMethod.GET)
	public String home() {
		logger.info("Welcome home!" );
		return "home.tiles";
	}
	
	
	@RequestMapping(value="/{group}/{type}/list.do", method=RequestMethod.GET)
	public String list(@PathVariable String group, @PathVariable String type, Map modelMap, Command command){
		
		command.setGroup(group);
		command.setType(type);
		
		String returnPage =  group+"/"+type+"/list.tiles";
		logger.info("RETURN: "+returnPage);
		
		homeService.list(modelMap, command);
		
		return returnPage;
	}
	
}

